package cn.tedu._05mvc.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tune_the last
 * @date 2025/11/10 - 18:12
 */
@RestController
public class BMIController {
    @RequestMapping("/bmi")
    public String getBMI(Double height, Double weight){
        if((weight / (height * height)) < 18.5){
            return "偏瘦";
        }
        if((weight / (height * height)) < 24){
            return "正常";
        }
        if((weight / (height * height)) < 27){
            return "微胖";
        }
        return "该减肥了";
    }

    /**
     * 路径中传递数据
     * 1.请求路径：/bmi/{height}/{weight}
     * 2.请求方法：GET
     * 3.请求参数：height，weight
     * 4.参数类型：路径参数
     * 5.返回响应：字符串类型
     */
    @GetMapping("/bmi/{height}/{weight}")
    public String bmi(@PathVariable Double weight, @PathVariable Double height){
        if((weight / (height * height)) < 18.5){
            return "偏瘦";
        }
        if((weight / (height * height)) < 24){
            return "正常";
        }
        if((weight / (height * height)) < 27){
            return "微胖";
        }
        return "该减肥了";
    }
}
